package com.sh.dao;

import com.sh.entity.UserPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IUserPermissionDao extends JpaRepository<UserPermission, Long>, JpaSpecificationExecutor<UserPermission> {

    @Query("select distinct u.bucket from UserPermission u where u.userId=:userId and  u.status = :status")
    List<String> listDistinctBucketByUserId(String userId, Integer status);

    @Query("select u.path from UserPermission u where u.userId=:userId and u.bucket=:bucket and  u.status = :status and u.level = (select min(u2.level) from UserPermission u2 where u2.level > 0)")
    List<String> findMaxLevelPermission(String userId,String bucket,Integer status);

}
